package com.lightsaber.trade.core.common.security;

import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

/**
 * 
 * @author LiuJian
 * 
 */
public class UserDetailsImpl extends User {

    private static final long serialVersionUID = 1L;

    private String[] roleList;

    public UserDetailsImpl(final String username, final String password, final boolean enabled,
            final boolean accountNonExpired, final boolean credentialsNonExpired,
            final boolean accountNonLocked,
            final Collection<? extends GrantedAuthority> authorities, final String[] roleList) {
        super(username, password, enabled, accountNonExpired, credentialsNonExpired,
                accountNonLocked, authorities);
        this.roleList = roleList;
    }

    public String[] getRoleList() {
        return roleList;
    }

    @Override
    public boolean equals(Object rhs) {
        if (rhs instanceof UserDetailsImpl) {
            UserDetailsImpl right = (UserDetailsImpl) rhs;
            return right.getUsername().equals(getUsername());

        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        return getUsername().hashCode();
    }

}
